package com.waitingresult.jdk8;

import com.waitingresult.entity.Student;

import java.util.ArrayList;

/**
 * @Author: WangShuai
 * @CreateTime: 2022-11-01  22:47
 * @Description: 函数式接口
 * @Version: 1.0
 */
public class Demo {
    public static void main(String[] args) {
        ArrayList<Student> studentData = getStudentData();
        ArrayList<Student> mans1 = findStudent(studentData, student -> "男".equals(student.getSex()));
        ArrayList<Student> mans2 = findStudent(studentData, Student::checkSexIsMan);
        ArrayList<Student> ages = findStudent(studentData, student -> student.getId() > 98);
        System.err.println(mans2);
    }

    public static ArrayList<Student> findStudent(ArrayList<Student> studentData, SelectCondition selectCondition) {
        ArrayList<Student> students = new ArrayList<>();
        for (Student studentDatum : studentData) {
            if (selectCondition.condition(studentDatum)) {
                students.add(studentDatum);
            }
        }
        return students;
    }

    private static ArrayList<Student> getStudentData() {
        ArrayList<Student> students = new ArrayList<>();
        for (long i = 0; i < 100; i++) {
            Student student = new Student(i, "姓名" + i);
            if (i % 2 == 0) {
                student.setSex("男");
            } else {
                student.setSex("女");
            }
            students.add(student);
        }
        return students;
    }
}
